package main

import (
	"fmt"
	"unsafe"
	"sync"
	"sync/atomic"
)

var ptr unsafe.Pointer=unsafe.Pointer(&[]int{})
var count=0

func write() {
	data:=[]int{}
	for i:=0;i<100;i++ {
		count++
		data=append(data,count)
	}

	atomic.StorePointer(&ptr, unsafe.Pointer(&data))
}

func read() {
	binPtr:=atomic.LoadPointer(&ptr)
	data:=*(*[]int)(binPtr)
	fmt.Println(data)
}

func main() {
	var wg sync.WaitGroup

	for i:=0;i<100;i++ {
		wg.Add(1)
		go func(){
			write()
			wg.Done()
		}()
	}

	for i:=0;i<100;i++ {
		wg.Add(1)
		go func(){
			read()
			wg.Done()
		}()
	}

	wg.Wait()
}
